package com.ruoyi.web.controller.wechatApplet;

import com.ruoyi.background.domain.AppGuestbook;
import com.ruoyi.background.service.IAppGuestbookService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/wechat/guest")
public class UserGuestbookController extends BaseController {


    @Autowired
    private IAppGuestbookService appGuestbookService;

    /**
     * 查询用户留言
     *
     * @param appGuestbook 查询列表条件
     * @return list
     */
    @GetMapping("getList")
    public TableDataInfo getGuestbook(AppGuestbook appGuestbook) {
        appGuestbook.setUserId(SecurityUtils.getUserId());
        startPage();
        List<AppGuestbook> guestbooks = appGuestbookService.selectAppGuestbookList(appGuestbook);
        return getDataTable(guestbooks);

    }

    /**
     * 用户新增留言
     *
     * @param appGuestbook 新的留言对象
     * @return 结果
     */
    @PostMapping("add")
    public AjaxResult userAddGuestbook(@RequestBody AppGuestbook appGuestbook) {
        appGuestbook.setUserId(SecurityUtils.getUserId());
        appGuestbook.setDeptId(SecurityUtils.getDeptId());
        return toAjax(appGuestbookService.insertAppGuestbook(appGuestbook));
    }


}
